package com.jinhua.huaojcodesandbox.exception;


import com.jinhua.huaojcodesandbox.model.ExecuteCodeResponse;
import com.jinhua.huaojcodesandbox.model.enums.QuestionSubmitJudgeInfoMessageEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 *
 * 
 * 
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public ExecuteCodeResponse businessExceptionHandler(BusinessException e) {
        log.error("BusinessException", e);
        return ResultUtils.error(e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public ExecuteCodeResponse runtimeExceptionHandler(RuntimeException e) {
        log.error("RuntimeException", e);
        return ResultUtils.error(QuestionSubmitJudgeInfoMessageEnum.UNKNOW_ERROR.getValue());
    }
}
